package VolumeMax;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class VolumeMaxFlowBean implements WritableComparable<VolumeMaxFlowBean> {
    private String symbol;
    private double volume;

    //2  反序列化时，需要反射调用空参构造函数
    public VolumeMaxFlowBean() {
    }

    //3  序列化方法
    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(symbol);
        dataOutput.writeDouble(volume);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        symbol = dataInput.readUTF();
        volume = dataInput.readDouble();
    }

    // 6 编写toString方法，方便后续打印到文本
    @Override
    public String toString() {
        return symbol +"\t" + volume;
    }

    public VolumeMaxFlowBean(String symbol, double volume) {
        this.symbol = symbol;
        this.volume = volume;
    }

    public String getSymbol() {
        return symbol;
    }

    public void setSymbol(String symbol) {
        this.symbol = symbol;
    }

    public double getVolume() {
        return volume;
    }

    public void setVolume(double volume) {
        this.volume = volume;
    }

    @Override
    public int compareTo(VolumeMaxFlowBean o) {
        int result;

        result = Double.compare(o.getVolume(), this.volume);

        return result;
    }
}
